home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6085 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  44 lines

  1. Path: fc.hp.com!news
  2. From: Rick Wells <rwells>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Do you have ever pass structures?
  5. Date: 22 Feb 1996 16:23:13 GMT
  6. Organization: Hewlett-Packard Fort Collins Site
  7. Message-ID: <4gi59h$alk@fcnews.fc.hp.com>
  8. References: <4ge8mi$qjm@srvr1.engin.umich.edu> <312BE9C9.67A2284E@eden.com>
  9. NNTP-Posting-Host: blkbear.fc.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/715)
  14. X-URL: news:312BE9C9.67A2284E@eden.com
  15.  
  16. > So is there any REAL advantage is passing an entire structure? Do people
  17. > ever do it? I've some people's source code and almost always, they
  18. > pass pointers to structures instead of the structure itself. In a way,
  19. > passing a pointer to an array instead of the array itself might be
  20. > feature not a bug in C. :)
  21.  
  22. Yes. Not usually though. Small structures work fine:
  23.  
  24. struct
  25. {
  26.     unsigned char    a;
  27.     unsigned char    b;
  28. } my_struct;
  29.  
  30. my_function (my_struct);
  31.  
  32. This may even be faster than passing a pointer. But if you are worried about
  33. speed to that degree at this point you should make your function a macro
  34. and compile it inline. My point is that for small structures it's a
  35. "don't care". For large structures you may care because it may take time and
  36. space to pass it by value.
  37.  
  38. As mentioned in a previous reply the only advantage to passing structures
  39. by value is the avoidance of accidental modification of the caller's data.
  40. That's a real advantage in some cases.
  41.  
  42. My opinion, Rick
  43.  
  44.